<?php


/** ensure this file is being included by a parent file */
defined('_JEXEC') or die('Restricted access');
?>

		<?php
		echo "<form action='{$this->formAction}' method='post' name='adminForm' id='adminForm'>";
		?>
		<table class="adminheading">
		<tr>
            <th class='helpdesk_fields'>
            <?php echo HelpDeskText::_( 'Fields' ); ?>
            </th>            
          <td class='right'>
          	<?php echo HelpDeskText::_( 'Search' ); ?>:
          </td>
          <td class="input">
          	<?php echo $this->search; ?>
          </td>
      		<?php
				for ($f=0; $f<count($this->filterLists); $f++) {
		          	echo "<td class='right'>";
					echo $this->filterLists[$f];
					echo "</td>";
				}
			?>
		</tr>
		</table>

		<table class="adminlist">
		<thead>
            <tr>
                <th width="20">
                	#
                </th>
                <th width="20">
                	<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count( $this->items ); ?>);" />
                </th>
                <th class="title">
                	<?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'ID' ), "id", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
                </th>                
                <th class="title">
                	<?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'Title' ), "title", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
                	+
                	<?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'DB Field Name' ), "fieldname", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
                </th>
                <th class="title">
                	<?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'Type' ), "typeid", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
                </th>
                <th class="title">
                	<center>
                	<?php echo HelpDeskHTML::sortList( HelpDeskText::_( 'Order' ), "ordering", $this->order_dir, $this->order, HelpDeskRequest::getVar( 'task' ) ); ?>
					<?php echo HelpDeskHTML::gridOrder( $this->items ); ?>
					</center>
                </th>
                <th class="title">
                	<center>
	                <?php echo HelpDeskText::_( 'Published' ); ?>
	                </center>
                </th>
                <th class="title">
                	<center>
	                <?php echo HelpDeskText::_( 'Categories' ); ?>
	                </center>
                </th>
            </tr>
		</thead>
        <tbody>
		<?php
        $k = 0;
        for ($i=0, $n=count( $this->items ); $i < $n; $i++)
        {
            $r = $this->items[$i];
            $checked    = HelpDeskHTML::gridId( $i, $r->id );
        	$published 	= HelpDeskHTML::gridPublished( $r, $i );
            $link 		= HelpDeskRoute::_( 'index2.php?option='.$option.'&controller='.$this->_name.'&task=edit&cid[]='. $r->id );
            $link_define = HelpDeskRoute::_( 'index2.php?option='.$option.'&controller='.$this->_name.'&task=define&id='. $r->id );           
    
	        echo "<tr class='row".$k."'>";
				echo "<td>"; echo $i + 1 + $this->pagination->limitstart; echo "</td>";
				echo "<td>$checked</td>";
	            echo "<td class='noborder'>"; 
					echo "<a href='".$link."'>$r->id</a>"; 
				echo "</td>";
	            echo "<td class='noborder'>"; 
	                echo "<a href='".$link."'>"; 
	                echo stripslashes($r->title);
	                echo "<br />&nbsp;&nbsp;&bull;&nbsp;&nbsp;";
	                echo $r->db_fieldname;
	                echo "</a>";
	            echo "</td>";
	            echo "<td class='noborder'>"; 
	                echo HelpDeskHelperField::getFieldTypeTitle( $r->typeid );
	            echo "</td>";
	            echo "<td class='noborder'>"; 
					?>
					<center>					
					<input type="text" name="ordering[<?php echo $r->id; ?>]" size="5" value="<?php echo $r->ordering; ?>" class="text_area" style="text-align: center" />
					</center>
					<?php
	            echo "</td>";								
	            echo "<td class='noborder'>"; 
					echo "<center>";
					echo $published;
	    	        echo "</center>";
	            echo "</td>";
	
	            echo "<td class='noborder'>";
					echo "<center>";
					echo $r->categories;
					echo "[<a href='{$link_define}'>".HelpDeskText::_( 'Select Categories' )."</a>]";
	    	        echo "</center>";
				echo "</td>";			
	        echo "</tr>";
        	if (isset($r->description) && strlen($r->description) > 1)  
			{ 
		        echo "<tr class='row".$k."'>";
	            echo "<td class='topnowrap' valign='top' nowrap>";
					$text_display = "[ + ]";
					$text_hide = "[ - ]";
					$onclick = "displayDiv(\"description_{$r->id}\", \"showhidedescription_{$r->id}\", \"{$text_display}\", \"{$text_hide}\");";
					echo "<span class='href' id='showhidedescription_{$r->id}' onclick='{$onclick}'>{$text_display}</span>";
	            echo "</td>";
	            echo "<td colspan='10'>"; 
					echo "<div id='description_{$r->id}' style='display: none;'>";
					echo nl2br( stripslashes( $r->description ) );
					echo "</div>";
	            echo "</td>";
		        echo "</tr>";
			}
        $k = 1 - $k;
        }
		
		if (!$this->items) {
			echo "<tr class='row".$k."'>";
				echo "<td class='topnowrap' colspan='10'>";
				echo HelpDeskText::_( 'None' );
				echo "</td>";
			echo "</tr>";		
		}
        ?>
        </tbody>
        <tfoot>
        	<tr>
                <td colspan='10'>
                    <div class="pagination">
                    <?php echo $this->pagination->getListFooter(); ?>
                    </div>            
                </td>
            </tr>
        </tfoot>

		</table>
                
		<input type="hidden" name="option" value="<?php echo $this->formOption; ?>" />
		<input type="hidden" name="controller" value="<?php echo $this->formController; ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="id" value="" />
		<input type="hidden" name="boxchecked" value="" />
		<input type="hidden" name="order" value="<?php echo $this->order; ?>" />
		<input type="hidden" name="order_dir" value="<?php echo $this->order_dir; ?>" />
        
		<?php
		echo $this->formValidate;
		echo "</form>";
		?>